package com.omega.encryptedsql.manager;

/**
 * @author omega
 * @description: TODO
 * @date 2025/7/10
 */
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class KeyManager {
    // 密钥映射: keyId -> secretKey
    private final Map<String, String> keyMap = new HashMap<>();

    public KeyManager(
            @Value("${encryption.keys.default}") String defaultKey,
            @Value("${encryption.keys.personal:}") String key1,
            @Value("${encryption.keys.payment:}") String key2) {

        keyMap.put("default", defaultKey);
        if (!key1.isEmpty()) keyMap.put("personal", key1);
        if (!key2.isEmpty()) keyMap.put("payment", key2);
    }

    public String getKey(String keyId) {
        return keyMap.getOrDefault(keyId, keyMap.get("default"));
    }
}